home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WUNZ20SR.ZIP / SIZEWNDW.C < prev    next >
C/C++ Source or Header  |  1993-04-30  |  5KB  |  131 lines

  1. #include "wizunzip.h"
  2.  
  3. /* sizewndw.c module of WizUnZip.
  4.  * Author: Robert A. Heath
  5.  * I, Robert Heath, place this source code module in the public domain.
  6.  */
  7.  
  8. #define MIN_LISTBOX_LINES 2
  9.  
  10. /* Call this when the window size changes or needs to change. */
  11. void SizeWindow(HWND hWnd, BOOL bOKtoMovehWnd)
  12. {
  13.     WORD wMinClientWidth;       /* minimum client width     */
  14.     WORD wButtonWidth;
  15.     int nListBoxHeight;         /* height of listbox in pix         */
  16.     WORD wVariableHeight;       /* no. variable pixels on client    */
  17.     WORD wVariableLines;            /* no. variable lines on client window */
  18.     WORD wMessageBoxHeight;     /* message box height in pixels     */
  19.     int nButtonsYpos;
  20.     WORD wClientWidth, wClientHeight;       /* size of client area  */
  21.     RECT rectT;             /* full window rectangle structure          */
  22.     int nCxBorder;
  23.     int nCyBorder;
  24.     int nCxVscroll; /* vertical scroll width */
  25.     int nCyHscroll; /* vertical scroll width */
  26.     int nCyCaption; /* caption height       */
  27.  
  28.     GetClientRect(hWnd, &rectT);
  29.     wClientWidth = rectT.right-rectT.left+1; /* x size of client area */
  30.     wClientHeight = rectT.bottom-rectT.top+1; /* y size of client area */
  31.     if (wWindowSelection == IDM_MAX_STATUS)
  32.     {
  33.         /* position the status window to fill entire client window   */
  34.         MoveWindow(hWndStatus, 0, 0, wClientWidth, wClientHeight, TRUE);
  35.         cLinesMessageWin = wClientHeight / dyChar ;
  36.         return;
  37.     }
  38.  
  39.     nCxBorder = GetSystemMetrics(SM_CXBORDER);
  40.     nCyBorder = GetSystemMetrics(SM_CYBORDER);
  41.     nCxVscroll = GetSystemMetrics(SM_CXVSCROLL);
  42.     nCyHscroll = GetSystemMetrics(SM_CYHSCROLL);
  43.     nCyCaption = GetSystemMetrics(SM_CYCAPTION);
  44.  
  45.     if (wClientHeight < (WORD)(11*dyChar))
  46.         wClientHeight = 11*dyChar;
  47.  
  48.     /* List Box gets roughly 1/2 of lines left over on client
  49.      * window after subtracting fixed overhead for borders,
  50.      * horizontal scroll bar,
  51.      * button margin spacing, header, and trailer lines.
  52.      * unless the status window is minimized
  53.      */
  54.     wVariableHeight =  wClientHeight - (2 * nCyBorder) - (6 * dyChar);
  55.     if (wWindowSelection != IDM_MAX_LISTBOX)
  56.         wVariableHeight -= nCyHscroll + nCyCaption + (2*nCyBorder) + dyChar;
  57.     wVariableLines = wVariableHeight / dyChar;
  58.     cListBoxLines =  (wWindowSelection == IDM_MAX_LISTBOX) ? 
  59.                     wVariableLines : wVariableLines / 2 ; 
  60.  
  61.     if (cListBoxLines < MIN_LISTBOX_LINES)
  62.         cListBoxLines = MIN_LISTBOX_LINES;
  63.  
  64.     cLinesMessageWin = wVariableLines - cListBoxLines; /* vis. msg. wnd lines */
  65.  
  66.     wMinClientWidth = 
  67.        (!uf.fFormatLong ? MIN_SHORT_FORMAT_CHARS : MIN_LONG_FORMAT_CHARS) * dxChar +
  68.                       nCxVscroll + 2 * nCxBorder;
  69.  
  70.     /* if we moved the hWnd from WM_SIZE, we'd probably get into
  71.      * a nasty, tight loop since this generates a WM_SIZE.
  72.      */
  73.     if (bOKtoMovehWnd && (wClientWidth < wMinClientWidth))
  74.     {
  75.         wClientWidth = wMinClientWidth;
  76.         GetWindowRect(hWnd, &rectT);
  77.         MoveWindow(hWnd, rectT.left, rectT.top,
  78.                     wClientWidth + (2*GetSystemMetrics(SM_CXFRAME)), wClientHeight,
  79.                     TRUE);
  80.     }
  81.  
  82.     /* divide buttons up into 4 equal zones each button separated by
  83.      * a 1-character buffer.
  84.      */
  85.     wButtonWidth = max( ((wClientWidth - 5 * dxChar)/4), 60 );
  86.  
  87.     nListBoxHeight = (cListBoxLines * dyChar) + (2 * nCyBorder);
  88.     MoveWindow(hWndList,        
  89.             0, dyChar,
  90.             wClientWidth,nListBoxHeight,
  91.             TRUE);
  92.  
  93.     nButtonsYpos = (cListBoxLines+3) * dyChar+ (dyChar/2) + (2 * nCyBorder);
  94.  
  95.     /* position the 4 buttons */
  96.     MoveWindow(hExtract, 
  97.             dxChar,nButtonsYpos,
  98.             wButtonWidth, 2 * dyChar,
  99.             TRUE);
  100.  
  101.     MoveWindow(hDisplay,
  102.             wButtonWidth+ (2 * dxChar), nButtonsYpos,
  103.             wButtonWidth, (2 * dyChar),
  104.             TRUE);
  105.  
  106.     MoveWindow(hTest,
  107.             2*(wButtonWidth+dxChar)+dxChar, nButtonsYpos,
  108.             wButtonWidth, (2 * dyChar),
  109.             TRUE);
  110.  
  111.     MoveWindow(hShowComment,
  112.             3*(wButtonWidth+dxChar)+dxChar, nButtonsYpos,
  113.             wButtonWidth, (2 * dyChar),
  114.             TRUE);
  115.  
  116.  
  117.     /* Position the status (Message) window.
  118.      * The Message windows is positioned relative to the bottom
  119.      * of the client area rather than relative to the top of the client.
  120.      */
  121.     wMessageBoxHeight = wVariableHeight - nListBoxHeight + 
  122.                         2 * nCyBorder + 
  123.                         nCyHscroll + nCyCaption ;
  124.  
  125.     MoveWindow(hWndStatus, 
  126.             0, wClientHeight - wMessageBoxHeight,
  127.             wClientWidth, wMessageBoxHeight,
  128.             TRUE);
  129.  
  130. }
  131.